package net.butfly.bus.server.invoker.impl;

import java.util.ArrayList;
import java.util.List;

import net.butfly.bus.Constants;
import net.butfly.bus.server.config.detail.RemoteConfig;
import net.butfly.albacore.exception.SystemException;


public class RemoteProvider extends ProviderBase {
	private RemoteConfig config;

	private static RemoteProvider instance = new RemoteProvider();

	public static RemoteProvider getInstance(Object config) {
		instance.config = (RemoteConfig) config;
		return instance;
	}

	@Override
	protected List<Object> getBeanList() {
		List<Object> beans = null;
		if (config.getBean() != null) {
			beans = new ArrayList<Object>();
			for (String clz : config.getBean()) {
				try {
					beans.add(Thread.currentThread().getContextClassLoader().loadClass(clz).newInstance());
				} catch (Exception ex) {
					throw new SystemException(Constants.BusinessError.BUSI_INSTANCE, ex);
				}
			}
		}
		return beans;
	}
}
